package com.wlz.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

import java.util.Arrays;

/**
 *  日志切面
 * @author wlz
 * @date 2022-05-28  9:26 下午
 */
public class MyLogXmlAspect {


	public void methodBefore(JoinPoint joinPoint) throws Throwable {
		String methodName = joinPoint.getSignature().getName();
		System.out.println("执行目标方法【"+methodName+"】的<前置通知>,入参"+ Arrays.asList(joinPoint.getArgs()));
	}

	public void methodAfter(JoinPoint joinPoint) {
		String methodName = joinPoint.getSignature().getName();
		System.out.println("执行目标方法【"+methodName+"】的<后置通知>,入参"+ Arrays.asList(joinPoint.getArgs()));
	}

	public void methodReturning(JoinPoint joinPoint, Object result) {
		String methodName = joinPoint.getSignature().getName();
		System.out.println("执行目标方法【"+methodName+"】的<返回通知>,入参"+Arrays.asList(joinPoint.getArgs()));
	}

	public void methodAfterThrowing(JoinPoint joinPoint) {
		String methodName = joinPoint.getSignature().getName();
		System.out.println("执行目标方法【"+methodName+"】的<异常通知>,入参"+Arrays.asList(joinPoint.getArgs()));
	}

	public Object methodAround(ProceedingJoinPoint point) throws Throwable {
		String methodName = point.getSignature().getName();
		System.out.println("执行目标方法【"+methodName+"】的<环绕通知>,入参"+Arrays.asList(point.getArgs()));
		Object[] args = point.getArgs();
		for(int i=0;i<args.length;i++){
			System.out.println("====args:"+args[i]);
			if(args[i].getClass().equals(String.class)){
				args[i] += "xxxx";
			}
		}

		// before
		Object result = point.proceed(args);

		// 处理逻辑
		System.out.println("执行目标方法【"+methodName+"】的<环绕通知>,结果"+ result.toString());
		return result;
	}

}
